# encoding: utf-8
module SinatraDemo
  module Routes
    class Artists < Base
      set :views, 'app/views/artists'
      get '/artists/new' do
        erb :new
      end
      post '/artists' do
        photo = params[:photo]
        pname = photo[:filename]
        photo = photo[:tempfile]
        artist = Artist.new do |a|
          a.name = params[:name]
          a.age = params[:age]
          a.photo = Sequel.blob(photo.read)
          a.pname = pname
        end.save
        redirect to("/artists/#{artist.id}")
      end
      get '/artists/:id' do
        @artist = Artist.find(:id=>params[:id])
        erb :show
      end
    end
  end
end